package bid.dao.impl;

import bid.dao.AreaDao;
import bid.entity.Area;
import bid.entity.Department;
import bid.util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
public class AreaDaoImpl implements AreaDao {
    @Override
    public List<Area> findAreas(String codeId, int level) {
        System.out.println("cod===="+codeId);
        String sql="select * from area where parentCodeId=?";

        List<Area> users = new ArrayList<>();
        Connection con = DBUtil.get();
        PreparedStatement st = null;
        ResultSet rs = null;
        try {
            st = con.prepareStatement(sql);//sql参数
            //填充占位符
            st.setString(1,codeId);
            rs = st.executeQuery();
            while (rs.next()) {
                Area user = new Area();
                user.setId(rs.getLong("id"));
                user.setCodeId(rs.getString("codeid"));
                user.setPositionName(rs.getString("positionName"));

                users.add(user);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(rs, st, con);
        }
        return users;
    }
}
